//
//  TFMemberCell.swift
//  TalkfunSDKDemo
//
//  Created by 邓盛明 on 2022/3/10.
//  Copyright © 2022 Talkfun. All rights reserved.
//

import UIKit


class TFMemberCell: UITableViewCell {
    @objc public let bgView = UIView.init()
    @objc public var avatarImageView:UIImageView!
    @objc public let nameAndmsgLab = UILabel.init()
    @objc public var cellwidth:CGFloat = 0
    //yes 横屏; no 竖屏
    @objc public var isOrientationLandscape:Bool = false

    @objc public var model:TFMember? {
        didSet {
            if ((model) != nil)
            {
                self.setModelUI(model: model!)
            }
        }
        
    }

    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
 
        self.bgView.backgroundColor = UIColor(red: 65/255.0, green: 150/255.0, blue: 235/255.0, alpha: 0.8)
        self.bgView.layer.cornerRadius = 14;
        self.bgView.layer.masksToBounds = true;
        self.contentView.addSubview(self.bgView)
      
        self.nameAndmsgLab.textColor = UIColor.white
        self.nameAndmsgLab.font = UIFont.PingFang(size: 14)
        self.nameAndmsgLab.lineBreakMode = .byCharWrapping;
        self.bgView.addSubview(self.nameAndmsgLab)
       
        self.avatarImageView = UIImageView.init()
        self.bgView.addSubview(self.avatarImageView)
      
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func setModelUI( model:TFMember) {
        self.avatarImageView.frame = CGRect(x: 6, y: 6, width: 20, height: 20)
        let str = model.nickname + "进入直播间"
        
        let rect = TalkfunSharedTools.getRectWith(str, size: CGSize(width: self.cellwidth-35-16-12-16, height: 20), fontSize: 14)
    
        
        self.nameAndmsgLab.frame = CGRect(x: self.avatarImageView.frame.maxX+8, y: 6, width: rect.size.width, height: 20)
     
        self.nameAndmsgLab.text = str;
        let url:URL? = URL.init(string: model.avatar)
        self.avatarImageView.sd_setImage(with: url, completed: nil)
       
        if (self.isOrientationLandscape) {
            self.bgView.frame = CGRect(x: 12, y: 4, width: rect.size.width+34+16, height: 32)
      
        } else {
            
            self.bgView.frame = CGRect(x: 12, y: 8, width: rect.size.width+34+16, height: 32)
        }
        
        
    }


}
